// =====================================================
// Feed API 服务
// =====================================================

import request from "../utils/request";
import type {
  Feed,
  FeedStats,
  RefreshResult,
  BatchRefreshResult,
} from "../types";

// 获取订阅源列表
export const getFeedList = () => {
  return request.get<any, Feed[]>("/feeds");
};

// 获取订阅源详情
export const getFeed = (id: number) => {
  return request.get<any, Feed>(`/feeds/${id}`);
};

// 添加订阅源
export const addFeed = (data: {
  url: string;
  title: string;
  category?: string;
}) => {
  return request.post<any, Feed>("/feeds", data);
};

// 更新订阅源
export const updateFeed = (
  id: number,
  data: { title: string; category: string; interval: number }
) => {
  return request.put<any, Feed>(`/feeds/${id}`, data);
};

// 删除订阅源
export const deleteFeed = (id: number) => {
  return request.delete<any, void>(`/feeds/${id}`);
};

// 切换订阅源启用状态
export const toggleFeedStatus = (id: number) => {
  return request.post<any, Feed>(`/feeds/${id}/toggle`);
};

// 刷新单个订阅源
export const refreshFeed = (id: number) => {
  return request.post<any, RefreshResult>(`/feeds/${id}/refresh`);
};

// 刷新所有订阅源
export const refreshAllFeeds = () => {
  return request.post<any, BatchRefreshResult>("/feeds/refresh-all");
};

// 获取订阅源统计
export const getFeedStats = () => {
  return request.get<any, FeedStats>("/feeds/stats");
};
